package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysGoodsFile;
import com.ruoyi.project.system.service.ISysGoodsFileService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商品文件Controller
 * 
 * @author jjp
 * @date 2020-04-21
 */
@RestController
@RequestMapping("/system/goodsfile/")
public class SysGoodsFileController extends BaseController
{
    @Autowired
    private ISysGoodsFileService sysGoodsFileService;

    /**
     * 查询商品文件列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGoodsFile sysGoodsFile)
    {
        startPage();
        List<SysGoodsFile> list = sysGoodsFileService.selectSysGoodsFileList(sysGoodsFile);
        return getDataTable(list);
    }

    /**
     * 获取商品文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(sysGoodsFileService.selectSysGoodsFileById(fileId));
    }

    /**
     * 新增商品文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "商品文件", businessType = BusinessType.INSERT)
    @PostMapping("addgGoodsFile")
    public AjaxResult add(@RequestBody SysGoodsFile sysGoodsFile)
    {
        return toAjax(sysGoodsFileService.insertSysGoodsFile(sysGoodsFile));
    }

    /**
     * 修改商品文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "商品文件", businessType = BusinessType.UPDATE)
    @PutMapping("updateGoodsFile")
    public AjaxResult edit(@RequestBody SysGoodsFile sysGoodsFile)
    {
        return toAjax(sysGoodsFileService.updateSysGoodsFile(sysGoodsFile));
    }

    /**
     * 删除商品文件
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "商品文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(sysGoodsFileService.deleteSysGoodsFileByIds(fileIds));
    }
}
